{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.调整卷积核的数量及卷积的大小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import absolute_import\n",
    "from __future__ import division\n",
    "from __future__ import print_function\n",
    "\n",
    "import argparse\n",
    "import sys\n",
    "import tensorflow as tf\n",
    "\n",
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "\n",
    "\n",
    "\n",
    "from keras.layers.core import Dense, Flatten\n",
    "from keras.layers.convolutional import Conv2D\n",
    "from keras.layers.pooling import MaxPooling2D\n",
    "\n",
    "from keras import backend as K\n",
    "import time\n",
    "from keras import initializers\n",
    "from keras.objectives import categorical_crossentropy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting /tmp/tensorflow/mnist/input_data\\train-images-idx3-ubyte.gz\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\train-labels-idx1-ubyte.gz\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "# Import data\n",
    "data_dir = '/tmp/tensorflow/mnist/input_data'\n",
    "mnist = input_data.read_data_sets(data_dir, one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define loss and optimizer\n",
    "x = tf.placeholder(tf.float32, [None, 784])\n",
    "y_ = tf.placeholder(tf.float32, [None, 10])\n",
    "learning_rate = tf.placeholder(tf.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def CONV(conv_n1 = 32, conv_n2 = 64, shape = [5, 5]):\n",
    "    with tf.name_scope('reshape'):\n",
    "        x_image = tf.reshape(x, [-1, 28, 28, 1])\n",
    "\n",
    "    net = Conv2D(conv_n1, kernel_size=shape, strides=[1,1],activation='relu', \n",
    "                     padding='same',\n",
    "                     kernel_initializer = initializers.TruncatedNormal(stddev=0.1), #卷积权重初始化\n",
    "                     bias_initializer = initializers.Zeros(), #偏置权重初始化\n",
    "                    input_shape=[28,28,1])(x_image)\n",
    "    net = MaxPooling2D(pool_size=[2,2])(net)\n",
    "    net = Conv2D(conv_n2, kernel_size=shape, strides=[1,1],activation='relu',\n",
    "                     kernel_initializer = initializers.TruncatedNormal(stddev=0.1),\n",
    "                     bias_initializer = initializers.Zeros(),\n",
    "                    padding='same')(net)\n",
    "    net = MaxPooling2D(pool_size=[2,2])(net)\n",
    "    net = Flatten()(net)\n",
    "    net = Dense(1000, activation='relu')(net) \n",
    "    net = Dense(10,activation='softmax')(net)\n",
    "\n",
    "    cross_entropy = tf.reduce_mean(categorical_crossentropy(y_, net))\n",
    "    l2_loss = tf.add_n( [tf.nn.l2_loss(w) for w in tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)] )\n",
    "\n",
    "    total_loss = cross_entropy + 7e-5*l2_loss\n",
    "\n",
    "    train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(total_loss)\n",
    "\n",
    "    sess = tf.Session()\n",
    "    K.set_session(sess)\n",
    "    init_op = tf.global_variables_initializer()\n",
    "    sess.run(init_op)\n",
    "    # Train\n",
    "    start = time.time()\n",
    "    for step in range(3000):\n",
    "        batch_xs, batch_ys = mnist.train.next_batch(100)\n",
    "        lr = 0.01\n",
    "        _, loss, l2_loss_value, total_loss_value = sess.run(\n",
    "                   [train_step, cross_entropy, l2_loss, total_loss], \n",
    "                   feed_dict={x: batch_xs, y_: batch_ys, learning_rate:lr})\n",
    "\n",
    "        if (step+1) % 100 == 0:\n",
    "            #print('step %d, entropy loss: %f, l2_loss: %f, total loss: %f' % \n",
    "             #  (step+1, loss, l2_loss_value, total_loss_value))\n",
    "            #Test trained model\n",
    "            correct_prediction = tf.equal(tf.argmax(net, 1), tf.argmax(y_, 1))\n",
    "            accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n",
    "            print(\"训练集准确度为\",sess.run(accuracy, feed_dict={x: batch_xs, y_: batch_ys}))\n",
    "        if (step+1) % 1000 == 0:\n",
    "            print(\"测试集准确度为\",sess.run(accuracy, feed_dict={x: mnist.test.images,\n",
    "                                        y_: mnist.test.labels}))\n",
    "            end = time.time()\n",
    "            print(\"%d步所用的时间为%fs\"%(step+1,end-start))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集准确度为 0.79\n",
      "训练集准确度为 0.84\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.95\n",
      "测试集准确度为 0.9425\n",
      "1000步所用的时间为112.323543s\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "测试集准确度为 0.9683\n",
      "2000步所用的时间为225.848720s\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9744\n",
      "3000步所用的时间为339.267987s\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "测试集准确度为 0.9612\n",
      "1000步所用的时间为181.740428s\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.9769\n",
      "2000步所用的时间为364.344602s\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.97\n",
      "测试集准确度为 0.981\n",
      "3000步所用的时间为544.255597s\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.9\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9649\n",
      "1000步所用的时间为269.502729s\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.9775\n",
      "2000步所用的时间为540.812180s\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9813\n",
      "3000步所用的时间为810.875067s\n"
     ]
    }
   ],
   "source": [
    "#所以对比均采用6个epoch作为参考\n",
    "#1.对比卷积的大小对准确度的影响\n",
    "shapes = [\n",
    "    [3,3],\n",
    "    [5,5],\n",
    "    [7,7],\n",
    "] \n",
    "for shape in shapes:\n",
    "    CONV(shape=shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "三个不同的卷积核中，[5,5],[7,7]与[3,3]相比，准确度有明显的提升，然而[7,7]比[5,5]稍高，却耗费更多的计算代价，因此卷积核的大小选择[5,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一层卷积的通道数为24,第二层卷积的通道数48\n",
      "训练集准确度为 0.89\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.9\n",
      "训练集准确度为 0.91\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.94\n",
      "测试集准确度为 0.9574\n",
      "1000步所用的时间为153.934998s\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "测试集准确度为 0.9757\n",
      "2000步所用的时间为310.043474s\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9788\n",
      "3000步所用的时间为465.427439s\n",
      "第一层卷积的通道数为24,第二层卷积的通道数64\n",
      "训练集准确度为 0.89\n",
      "训练集准确度为 0.91\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.95\n",
      "测试集准确度为 0.9576\n",
      "1000步所用的时间为174.797703s\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "测试集准确度为 0.9739\n",
      "2000步所用的时间为350.803262s\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.9802\n",
      "3000步所用的时间为526.764787s\n",
      "第一层卷积的通道数为24,第二层卷积的通道数80\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.91\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "测试集准确度为 0.9568\n",
      "1000步所用的时间为193.271778s\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9728\n",
      "2000步所用的时间为385.745990s\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.979\n",
      "3000步所用的时间为578.384319s\n",
      "第一层卷积的通道数为32,第二层卷积的通道数48\n",
      "训练集准确度为 0.82\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.89\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.97\n",
      "测试集准确度为 0.9614\n",
      "1000步所用的时间为199.428771s\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "测试集准确度为 0.9748\n",
      "2000步所用的时间为399.229168s\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9803\n",
      "3000步所用的时间为600.451571s\n",
      "第一层卷积的通道数为32,第二层卷积的通道数64\n",
      "训练集准确度为 0.86\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.88\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.98\n",
      "测试集准确度为 0.9643\n",
      "1000步所用的时间为220.843919s\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.9764\n",
      "2000步所用的时间为441.808294s\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.9811\n",
      "3000步所用的时间为662.755657s\n",
      "第一层卷积的通道数为32,第二层卷积的通道数80\n",
      "训练集准确度为 0.91\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.89\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.96\n",
      "测试集准确度为 0.9624\n",
      "1000步所用的时间为242.792074s\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9746\n",
      "2000步所用的时间为486.384463s\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9797\n",
      "3000步所用的时间为730.955353s\n",
      "第一层卷积的通道数为40,第二层卷积的通道数48\n",
      "训练集准确度为 0.87\n",
      "训练集准确度为 0.9\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.94\n",
      "测试集准确度为 0.961\n",
      "1000步所用的时间为244.874571s\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.976\n",
      "2000步所用的时间为488.831218s\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.9789\n",
      "3000步所用的时间为732.767850s\n",
      "第一层卷积的通道数为40,第二层卷积的通道数64\n",
      "训练集准确度为 0.88\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.96\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.92\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "测试集准确度为 0.9587\n",
      "1000步所用的时间为266.891928s\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.94\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "测试集准确度为 0.9776\n",
      "2000步所用的时间为532.877164s\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "测试集准确度为 0.9814\n",
      "3000步所用的时间为798.537560s\n",
      "第一层卷积的通道数为40,第二层卷积的通道数80\n",
      "训练集准确度为 0.89\n",
      "训练集准确度为 0.9\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.93\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.9669\n",
      "1000步所用的时间为291.008379s\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.95\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "测试集准确度为 0.978\n",
      "2000步所用的时间为581.351846s\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.98\n",
      "训练集准确度为 0.97\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.99\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 1.0\n",
      "训练集准确度为 0.98\n",
      "测试集准确度为 0.9807\n",
      "3000步所用的时间为874.565474s\n"
     ]
    }
   ],
   "source": [
    "#改变第一层卷积的通道数\n",
    "cs1 = [24,32,40]\n",
    "cs2 = [48,64,80]\n",
    "for conv_n1 in cs1:\n",
    "    for conv_n2 in cs2:        \n",
    "        print(\"第一层卷积的通道数为%d,第二层卷积的通道数%d\"%(conv_n1,conv_n2))\n",
    "        CONV(conv_n1 = conv_n1,conv_n2 = conv_n2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从上述数据可以看出，选取通道数越多，准确度越大，但是随着通道数的增多，准确度增加的不明显，反而明显加大计算时间，\n",
    "因此可选取中间值，使准确度达到一定值的同时，训练时间不至于太高\n",
    "其中第一层卷积核通道数为32，第二层卷积核通道数为64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
